//
//  CrazyChatMineImageCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/15.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatMineImageCell.h"
#import "FLAnimatedImageView.h"

@interface CrazyChatMineImageCell ()

@property (nonatomic, strong) UIImageView *mineHeadImageView; //头像
@property (nonatomic, strong) UIView *mineImageBackView; //背景
@property (nonatomic, strong) FLAnimatedImageView *mineImageView; //图片

@end

@implementation CrazyChatMineImageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = CrazyChatMineImageIdentifier;
    
    //缓存中取
    CrazyChatMineImageCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell) {
        cell = [[CrazyChatMineImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        self.mineHeadImageView = [[UIImageView alloc] init];
        self.mineHeadImageView.frame = CGRectMake(CRAZY_SCREEN_WIDTH - 55, 10, 40, 40);
        [self.contentView addSubview:self.mineHeadImageView];
        //背景
        self.mineImageBackView = [[UIView alloc] init];
        self.mineImageBackView.frame = CGRectMake(CRAZY_SCREEN_WIDTH - 160, 10, 100, 100);
        [self.contentView addSubview:self.mineImageBackView];
        //图片
        self.mineImageView = [[FLAnimatedImageView alloc] init];
        self.mineImageView.frame = self.mineImageBackView.bounds;
        [self.mineImageBackView addSubview:self.mineImageView];
        //重发按钮
        self.mineImageRepeatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mineImageRepeatBtn setImage:[UIImage imageNamed:@"Crazy_chat_repeat.png"] forState:UIControlStateNormal];
        self.mineImageRepeatBtn.size = CGSizeMake(30, 30);
        self.mineImageRepeatBtn.x = 20;
        self.mineImageRepeatBtn.y = 10 + self.mineImageBackView.height / 2 - 15;
        [self.contentView addSubview:self.mineImageRepeatBtn];
    }
    return self;
}

//赋值
- (void)setCellValueWithHeadURL:(NSString *)headURL picURL:(NSString *)picURL repeatType:(NSString *)repeatType {
    //头像
    [self.mineHeadImageView sd_setImageWithURL:[NSURL URLWithString:headURL] placeholderImage:CRAZY_DEFAULT_HEADIMAGE];
    //图片
    [self.mineImageView sd_setImageWithURL:[NSURL URLWithString:picURL] placeholderImage:CRAZY_DEFAULT_LOADIMAGE];
    //重发按钮
    if ([repeatType isEqualToString:@"1"]) {
        self.mineImageRepeatBtn.hidden = NO;
    } else {
        self.mineImageRepeatBtn.hidden = YES;
    }
}





- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
